package com.atues.thread.multiy;

public class ThreadLocal1 {


        private static final ThreadLocal<String> userThreadLocal = new ThreadLocal<>();
        private static final ThreadLocal<Integer> countThreadLocal = new ThreadLocal<>();

        public static void main(String[] args) {
            // 线程1
            new Thread(() -> {
                userThreadLocal.set("User1");
                countThreadLocal.set(100);
                System.out.println(userThreadLocal.get());  // 输出 User1
                System.out.println(countThreadLocal.get()); // 输出 100
            }).start();

            // 线程2
            new Thread(() -> {
//                userThreadLocal.set("User2");
                countThreadLocal.set(200);
                System.out.println(userThreadLocal.get());  // 输出 User2
                System.out.println(countThreadLocal.get()); // 输出 200
            }).start();
        }

}
